package com.itheima.advantagesup.controller;

import com.itheima.advantagesup.common.R;
import com.itheima.advantagesup.dto.SyssMenuDTO;
import com.itheima.advantagesup.service.SysMenuService;
import com.itheima.advantagesup.vo.MenuVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/sys_menu")
public class SystemMenuController {
    @Autowired
    private SysMenuService sysMenuService;
    //查询菜单
    @GetMapping("/allData")
    public R findAllMenu(){
        log.info("查询所有菜单");
        List<MenuVO> menu=sysMenuService.findAllMenu();
        return R.success(menu);
    }
    //添加菜单
    @PostMapping("/add")
    public R AddMenu(@RequestBody SyssMenuDTO syssMenuDTO){
        log.info("添加菜单:{}",syssMenuDTO);
        sysMenuService.AddMenu(syssMenuDTO);
        return R.success();
    }
    //删除菜单
    @GetMapping("/del")
    public R DeleteId( Integer id){
        log.info("删除菜单:{}",id);
        sysMenuService.DeleteId(id);
        return R.success();
    }
    //根据id查询菜单进行修改
    @GetMapping("/rowInfo")
    public R findById(Integer id){
        log.info("根据id查询菜单进行修改:{}",id);
        MenuVO menu=sysMenuService.findById(id);
        return R.success(menu);
    }

    //根据id进行修改
    @PostMapping("/update")
    public R updateById(@RequestBody SyssMenuDTO syssMenuDTO){
        log.info("根据id进行修改:{}",syssMenuDTO);
        sysMenuService.updateById(syssMenuDTO);
        return R.success();
    }
}
